﻿using System;
using System.Collections;
using System.Collections.Generic;

class Knight
{
    public struct Coordinates
    {
        public int X;
        public int Y;
        public char ch;
        public int depth;
    }

    static void Main()
    {
        Queue<Coordinates> move = new Queue<Coordinates>();
        int row = int.Parse(Console.ReadLine());
        List<List<char>> squares = new List<List<char>>();
        Coordinates startCoord = new Coordinates();

        // Initializing the rows of the square
        for (int i = 0; i < row; i++)
        {
            squares.Add(new List<char>());
        }

        // Filling the list with chars
        for (int i = 0; i < row; i++)
        {
            string input = Console.ReadLine();

            for (int k = 0, j = 0; k < input.Length; k += 2, j++)
            {
                squares[i].Add(input[k]);

                if (input[k] == 's')
                {
                    startCoord.Y = i;
                    startCoord.X = j;
                    startCoord.depth = 's';
                    startCoord.depth = 0; // First depth
                    move.Enqueue(startCoord);
                }
            }
        }

        int col = squares[0].Count;
        int currentDepth = 0;
        bool foundPath = false;

        // BFS       
        while (move.Count != 0)
        {
            Coordinates nodeCoord = move.Dequeue();
            currentDepth = nodeCoord.depth;

            if (nodeCoord.ch == 'e')
            {
                foundPath = true;
                break;
            }

            // Checking every possible jump of the knight
            int[,] possibleJumps = new int[2, 8];
            int X = nodeCoord.X;
            int Y = nodeCoord.Y;

            possibleJumps[0, 0] = X - 2;
            possibleJumps[1, 0] = Y + 1;

            possibleJumps[0, 1] = X - 1;
            possibleJumps[1, 1] = Y + 2;

            possibleJumps[0, 2] = X + 1;
            possibleJumps[1, 2] = Y + 2;

            possibleJumps[0, 3] = X + 2;
            possibleJumps[1, 3] = Y + 1;

            possibleJumps[0, 4] = X + 2;
            possibleJumps[1, 4] = Y - 1;

            possibleJumps[0, 5] = X + 1;
            possibleJumps[1, 5] = Y - 2;

            possibleJumps[0, 6] = X - 1;
            possibleJumps[1, 6] = Y - 2;

            possibleJumps[0, 7] = X - 2;
            possibleJumps[1, 7] = Y - 1;

            bool isInCurrentDepth = false;

            for (int i = 0; i < 8; i++)
            {
                int possX = possibleJumps[0, i];
                int possY = possibleJumps[1, i];

                if (possX >= 0 && possX < col && possY >= 0 && possY < row)
                {
                    if (squares[possY][possX] != 'x')
                    {
                        if (!isInCurrentDepth)
                        {
                            currentDepth++;
                            isInCurrentDepth = true;
                        }

                        Coordinates newNode = new Coordinates();
                        newNode.X = possX;
                        newNode.Y = possY;
                        newNode.ch = squares[possY][possX];
                        newNode.depth = currentDepth;
                        move.Enqueue(newNode);
                        // Mark as visited
                        squares[possY][possX] = 'x';
                    }
                }
            }

        }

        // Output
        if (foundPath)
        {
            Console.WriteLine(currentDepth);
        }
        else
        {
            Console.WriteLine(-1);
        }
    }
}